package speed2010.andreza.vspeed.ontologies;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;

public class SummarizedOntology {
	
	private ArrayList<OntologyConcept> concepts;
	private String IPaddress;
	private static int maxSize = 6;
	
	public SummarizedOntology(String address)
	{
		this.concepts = new ArrayList<OntologyConcept>(maxSize);
		this.IPaddress = address;
	}
	
	@SuppressWarnings("unchecked")
	public void addConcept(String concept)
	{
		this.concepts.add(new OntologyConcept(concept));
		Collections.sort(this.concepts);
	}
	
	public SummarizedOntology(int n)
	{
		this.concepts = new ArrayList<OntologyConcept>(n);
	}
	
	public ArrayList<OntologyConcept> getConcepts()
	{
		return this.concepts;
	}
	
	public int getMaxSummarySize()
	{
		return this.maxSize;
	}
	
	public void summarize(Ontology ontology)
	{
		ArrayList<OntologyConcept> concepts = ontology.getConcepts();
		Collections.sort(concepts);
		
		for(int i = 0; i < concepts.size() && i < this.maxSize; i++)
		{
			this.concepts.add(concepts.get(i));
		}
	}
	
	public static int getMaxSize() {
		return maxSize;
	}

	public static void setMaxSize(int maxSize) {
		SummarizedOntology.maxSize = maxSize;
	}
	
	public String getIPaddress() {
		return IPaddress;
	}
	
	public boolean equals(Object o)
	{
		SummarizedOntology summary = (SummarizedOntology) o;
		if(this.IPaddress.equals(summary.IPaddress))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	
	
	public String toString()
	{
		String s = "";
		s = s + "<<Cluster: " + this.getIPaddress() + ">>\r\n";
		
		Iterator<OntologyConcept> conceptsIterator = this.concepts.iterator();
		
		while(conceptsIterator.hasNext())
		{
			OntologyConcept concept = conceptsIterator.next();
			s = s + "  " + concept + "\r\n";
		}
		
		return s;
	}

}
